package Test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

class IntCmp implements Comparator<Integer>{
	@Override
  public int compare(Integer o1,Integer o2) {
		return o2-o1;
	}
	
public class Test {
public  static int[] topK(int[] array,int k) {
	IntCmp intCmp = new IntCmp();
	PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(intCmp);
	for(int i = 0;i<array.length;i++) {
		priorityQueue.offer(array[i]);//插入堆中
	}//大堆创建完毕
	int[] ret = new int[k];
	for(int i = 0;i<k;i++) {
		int val = priorityQueue.poll();
		ret[i] = val;
	}
	return ret;
}
public static void main(String[] args) {
	int[] array = {10,4,20,19,45,20};
	int[]ret= topK(array,3);
	System.out.println(Arrays.toString(ret));
}

}
}
